﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;


namespace QuanLySimSoDep
{
    public partial class quanlysim : Form
    {
        public bool kiemtra = false;
        public quanlysim()
        {
            InitializeComponent();
        }

        private void btn_KiemTraMang_Click(object sender, EventArgs e)
        {
            string strNhamang = "";
            string strSoSim = txt_NhapSim.Text;
            int iDodai = strSoSim.Length;
            

            if (iDodai == 10)
            {
                string dauso = strSoSim.Substring(0, 3);

                if (dauso == "091" || dauso == "094")
                {
                    
                    strNhamang = "Vina";
                    kiemtra = true;
                    
                }
                else if (dauso == "090" || dauso == "093")
                {
                    strNhamang = "Mobi";
                    kiemtra = true;
                    
                }
                else if (dauso == "097" || dauso == "098")
                {
                    strNhamang = "Viettel";
                    kiemtra = true;

                }
                else if (dauso == "092")
                {
                    strNhamang = "Vietnammobile";
                    kiemtra = true;
                }
                else if (dauso == "095")
                {
                    strNhamang = "Sfone";
                    kiemtra = true;
                }
                else
                {
                    strNhamang = "không xác định";
                    kiemtra = false;
                }

            }
            else if (iDodai == 11)
            {
                string dauso = strSoSim.Substring(0, 4);

                if (dauso == "0123" || dauso == "0125" || dauso == "0127")
                {
                    strNhamang = "Vina";
                    kiemtra = true;
                }
                else if (dauso == "0121" || dauso == "0122" || dauso == "0126" || dauso == "0128")
                {
                    strNhamang = "Mobi";
                    kiemtra = true;
                }
                else if (dauso == "0169" || dauso == "0168" || dauso == "0167" || dauso == "0166" || dauso == "0165")
                {
                    strNhamang = "Viettel";
                    kiemtra = true;

                }
                else if (dauso == "0199")
                {
                    strNhamang = "Beline";
                    kiemtra = true;
                }

            }
            else
            {
                strNhamang = "So sim khong hop le";
                kiemtra = false;
            }
            lbl_NhaMang.Text = strNhamang;
            if(kiemtra = true)
            {
                this.btn_ok.Enabled = true;
            }
            else
            {
                this.btn_ok.Enabled = false;
            }
        }

        private void txt_NhapSim_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                MessageBox.Show("Yeu Cau Nhap So");
            }

        }

        private void txt_Gia_TextChanged(object sender, EventArgs e)
        {

        }

        private void txt_Gia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                MessageBox.Show("Yeu Cau Nhap So");
            }

        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            
            StreamWriter sw = new StreamWriter("dulieu.txt",true);
            sw.WriteLine(txt_NhapSim.Text);
            sw.WriteLine(txt_Gia.Text);
            sw.WriteLine(lbl_NhaMang.Text);
            sw.Close();
          
        }
    }
}
